<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <!-- <input type="text" id="num" value="" /><button id="but">提交</button>
    <script>
      var inputElement = document.getElementById("num");
      var buttonElement = document.getElementById("but");
      but.onclick = function () {
        var num = parseInt(inputElement.value);
        if (num >= 1) {
          alert("大于零");
        } else if (num <= -1) {
          alert("小于零");
        } else if (num == 0) {
          alert("等于零");
        }
      };
    </script> -->
    <!-- <input type="text" id="num" value="" /><button id="but">提交</button>
    <script>
      var inputElement = document.getElementById("num");
      var buttonElement = document.getElementById("but");
      but.onclick = function () {
        var num = parseInt(inputElement.value);
        if (num % 2 !== 0) {
          alert("奇数");
        } else if (num % 2 == 0) {
          alert("偶数");
        }
      };
    </script> -->
    <!-- <input type="text" id="num" value="" /><button id="but">提交</button>
    <script>
      var inputElement = document.getElementById("num");
      var buttonElement = document.getElementById("but");
      but.onclick = function () {
        var num = parseInt(inputElement.value);
        if ((num % 4 == 0 && num % 100 !== 0) || num % 400 == 0) {
          alert("闰年");
        } else {
          alert("平年");
        }
      };
    </script> -->

    <!-- 输入身高：<input type="text" id="num1" value="" /> 输入体重：<input
      type="text"
      id="num2"
      value=""
    />
    <button id="but">点击</button>
    <script>
      var num1Element = document.getElementById("num1");
      var num2Element = document.getElementById("num2");
      var buttonElement = document.getElementById("but");
      but.onclick = function () {
        var num1 = parseInt(num1Element.value);
        var num2 = parseInt(num2Element.value);
        var num3 = (num1 - 108) * 2;
        if (Math.abs(num3 - num2) <= 10) {
          // if ((num1 - 108) * 2 >= num2 - 10 && (num1 - 108) * 2 <= num2 + 10) {
          alert("标准体重");
        } else {
          alert("非标准体重");
        }
      };
    </script> -->
    <!-- <input type="text" id="num1" />
    <select name="" id="sel">
      <option value="+">+</option>
      <option value="-">-</option>
      <option value="*">*</option>
      <option value="/">/</option>
    </select>
    <input type="text" id="num2" />
    <button id="but">提交</button>
    结果：<input type="text" id="end" />
    <script>
      var num1ELe = document.getElementById("num1");
      var selELe = document.getElementById("sel");
      var num2ELe = document.getElementById("num2");
      var butELe = document.getElementById("but");
      var endELe = document.getElementById("end");
      but.onclick = function () {
        var num1 = parseInt(num1ELe.value);
        var num2 = parseInt(num2ELe.value);
        var sel = selELe.value;
        if (sel == "+") {
          var end = num1 + num2;
        } else if (sel == "-") {
          var end = num1 - num2;
        } else if (sel == "*") {
          var end = num1 * num2;
        } else if (sel == "/") {
          var end = num1 / num2;
        }
        console.log(end);
        endELe.value = end;
      };
    </script> -->
    输入年份:<input type="text" id="year" /> 输入月份:
    <input type="text" id="month" /> 输入天数: <input type="text" id="day" />
    <button id="but">计算</button>
    <script>
      var yearEle = document.getElementById("year");
      var monthEle = document.getElementById("month");
      var dayEle = document.getElementById("day");
      var butEle = document.getElementById("but");
      but.onclick = function () {
        var year = parseInt(yearEle.value);
        var month = parseInt(monthEle.value);
        var day = parseInt(dayEle.value);

        if ((year % 4 == 0 && year % 100 !== 0) || year % 400 == 0) {
          var feb = 29;
        } else {
          var feb = 28;
        }
        // console.log(feb);
        var num = 1;
        var totalDay = 0;
        while (num < month) {
          // console.log(num);
          if (
            num == 1 ||
            num == 3 ||
            num == 5 ||
            num == 7 ||
            num == 8 ||
            num == 10
          ) {
            totalDay += 31;
          }
          if (num == 2) {
            totalDay += feb;
          }
          // 需要加上30天的月份
          if (num == 4 || num == 6 || num == 9 || num == 11) {
            totalDay += 30;
          }
          num++;
        }

        var res = totalDay + day;
        alert(res);
      };
    </script>
  </body>
</html>
